package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.request.UpdateLabelRequest;
import com.ytjj.qmyx.admin.service.ProductLabelService;
import com.ytjj.qmyx.admin.utils.UserUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 
 * 
 * @Version: 1.0
 */
@RestController
@RequestMapping("/productLabel")
public class ProductLabelController {

    @Resource
    private ProductLabelService productLabelService;

    /**
     *  分页查询
     * @param productLabelName 标签名
     * @param pageNum 页码
     * @param pageSize 数量
     * @return CommonResult
     */
    @GetMapping("/select")
    public CommonResult select(@RequestParam(value = "productLabelName", required = false) String productLabelName,
                               @RequestParam(value = "pageNum", defaultValue = "1", required = false)Integer pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "10", required = false)Integer pageSize) {
        return productLabelService.select(productLabelName,pageNum,pageSize);
    }

    /**
     * 增加修改标签
     * @param productLabelName 名
     * @param productLabelId id
     * @return CommonResult
     */
    @GetMapping("/addAndUpdate")
    public CommonResult addAndUpdate(@RequestParam(value = "productLabelName") String productLabelName,
                                     @RequestParam(value = "productLabelId",required = false) Integer productLabelId,
                                     @RequestParam(value = "colour") String colour) {
//        Integer adminId = UserUtil.getAdminId();
        return productLabelService.addAndUpdate(productLabelName,productLabelId,1,colour);
    }


    /**
     *  删除标签
     * @param productLabelId 标签id
     * @return CommonResult
     */
    @GetMapping("/delete")
    public CommonResult delete(@RequestParam(value = "productLabelId") Integer productLabelId) {
        return productLabelService.delete(productLabelId);
    }

    /**
     *  查询所有标签
     * @return CommonResult
     */
    @GetMapping("/selectAll")
    public CommonResult selectAll() {
        return productLabelService.selectAll();
    }

    /**
     * 新增商品 关联 标签 的数据
     */
    @PostMapping("/addProductLabel")
    public CommonResult addProductLabel(@RequestBody UpdateLabelRequest updateLabelRequest) {
        Integer adminId = UserUtil.getAdminId();
        return productLabelService.addProductLabel(updateLabelRequest.getProductIds(),updateLabelRequest.getProductLabelIds(),adminId);
    }

    /**
     * 批量移除商品的标签
     */
    @PostMapping("/batchDeleteProductLabel")
    public CommonResult batchDeleteProductLabel(@RequestBody UpdateLabelRequest request) {
        return productLabelService.batchDeleteProductLabel(request.getProductIds());
    }
}
